<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.BufferContext</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_buffer_context_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../'>Howl 0.3 Documentation</a></li><li>Spec</li><li>Spec - howl.BufferContext</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.buffercontext">howl.BufferContext</h1>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">b</span><span class="w">&#x000A;&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'"HƏllo", said Mr.Bačon'</span><span class="w">&#x000A;&#x000A;</span><span class="n">context_at</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">pos</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nc">BufferContext</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="n">pos</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".word_prefix-holds-the-words's-text-up-until-pos">.word_prefix holds the words's text up until pos</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">2</span><span class="p">).</span><span class="n">word_prefix</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'HƏ'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">4</span><span class="p">).</span><span class="n">word_prefix</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".word_suffix-holds-the-words's-text-after-and-including-pos">.word_suffix holds the words's text after and including pos</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'HƏllo'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">2</span><span class="p">).</span><span class="n">word_suffix</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'llo'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">4</span><span class="p">).</span><span class="n">word_suffix</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".prefix-holds-the-line's-text-up-until-pos">.prefix holds the line's text up until pos</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="n">prefix</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'"HƏllo", said Mr.Bačon'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="o">#</span><span class="n">b</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">).</span><span class="n">prefix</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'"H'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">3</span><span class="p">).</span><span class="n">prefix</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".suffix-holds-the-line's-text-after-and-including-pos">.suffix holds the line's text after and including pos</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="o">#</span><span class="n">b</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">).</span><span class="n">suffix</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'"HƏllo", said Mr.Bačon'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="n">suffix</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Mr.Bačon'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">15</span><span class="p">).</span><span class="n">suffix</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".next_char-holds-the-current-character-or-the-empty-string-if-none">.next_char holds the current character or the empty string if none</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Ə'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">3</span><span class="p">).</span><span class="n">next_char</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="o">#</span><span class="n">b</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">).</span><span class="n">next_char</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".prev_char-holds-the-previous-character-or-the-empty-string-if-none">.prev_char holds the previous character or the empty string if none</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Ə'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">4</span><span class="p">).</span><span class="n">prev_char</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="n">prev_char</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".line-holds-the-current-line-object">.line holds the current line object</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="n">line</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".style-holds-the-style-at-point">.style holds the style at point</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">ActionBuffer</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'['</span><span class="p">,</span><span class="w"> </span><span class="s1">'operator'</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'"foo"'</span><span class="p">,</span><span class="w"> </span><span class="s1">'string'</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">' normal'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'operator'</span><span class="p">,</span><span class="w"> </span><span class="nc">BufferContext</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">).</span><span class="n">style</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'string'</span><span class="p">,</span><span class="w"> </span><span class="nc">BufferContext</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">).</span><span class="n">style</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'unstyled'</span><span class="p">,</span><span class="w"> </span><span class="nc">BufferContext</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="p">).</span><span class="n">style</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="contexts-are-equal-for-the-same-buffer-and-pos">contexts are equal for the same buffer and pos</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">2</span><span class="p">),</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">not_equal</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">2</span><span class="p">),</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".word">.word</h2>&#x000A;&#x000A;<h4 id="holds-the-current-word">holds the current word</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'HƏllo'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">2</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'HƏllo'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">4</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'HƏllo'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">6</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">8</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">9</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'said'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">14</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Mr'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">16</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Bačon'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">19</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'first'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'first'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="the-word-boundaries-are-determined-using-the-variable-word_pattern">the word boundaries are determined using the variable word_pattern</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">word_pattern</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'[Əl]+'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Əll'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">3</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">word_pattern</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'["Ə%w]+'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'"HƏllo"'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">3</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'"HƏllo"'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">8</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="c1">-- after "</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">9</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="c1">-- after ','</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="the-word_pattern-can-be-a-regex">the word_pattern can be a regex</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">word_pattern</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">r</span><span class="s1">'\\pL+'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'HƏllo'</span><span class="p">,</span><span class="w"> </span><span class="n">context_at</span><span class="p">(</span><span class="mi">3</span><span class="p">).</span><span class="n">word</span><span class="p">.</span><span class="n">text</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2015
            <a class='alert-link' href='https://github.com/nilnor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
